﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace xDOMv1.PRE
{
    public partial class frmConfig : Form
    {
        public frmConfig()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            // LINQ to SQL class
            string strLS = @"Data Source=" + cbbServer.Text
                + @";Initial Catalog=" + cbbDb.Text
                + @";Persist Security Info=True;User ID=" + txtUser.Text
                + ";Password=" + txtPass.Text;

            // ADO.NET Entity Data Model
            //string strEF = @"metadata=res://*/DAL.EF.xPOSv2.csdl|res://*/DAL.EF.xPOSv2.ssdl|res://*/DAL.EF.xPOSv2.msl;provider=System.Data.SqlClient;provider connection string='"
                //+ strLS + ";MultipleActiveResultSets=True'";

            Configuration _config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);            
            _config.ConnectionStrings.ConnectionStrings[1].ConnectionString = strLS;
            _config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection(_config.ConnectionStrings.SectionInformation.Name);
            Properties.Settings.Default.Reload();

            this.Close();
        }
    }
}
